<template>
  <div class="container">
    <result v-if="isShow == 1" :showStatu="showStatu" :isObtain="isObtain" :isTeamObtain="isTeamObtain"></result>

    <inputPhone v-if="isShow == 2" :on-success="receviceData"></inputPhone>

    <play-game-com v-if="isShow == 3"></play-game-com>

    <div v-if="isShow == 4">
      <img :src="totalPic.index1" alt>
      <img class="start-btn" @click="startBtn" :src="totalPic.borderRadius" alt>
      <img class="dai" :src="totalPic.dai" alt>
    </div>
  </div>
</template>

<script>
import { filterPic } from "./apis/utils.js";
import playGameCom from "./component/playGame";
import inputPhone from "./component/inputPhone";
import result from "./component/result";
import { ifHomeCake, setEstablishCake } from "./apis/apis.js";
import VConsole from "VConsole";
import { setTimeout } from "timers";
export default {
  data() {
    return {
      num: 0,
      isShow: 0,
      isObtain: 0,
      showStatu: "4",
      isTeamObtain: 0,
      totalPic: {},
      isPlayGame: false
    };
  },

  created() {
    var that = this;
    const imgUrl = {
      index1: "1.jpg",
      borderRadius: "border-radius.png",
      dai: "dai.gif"
    };
    this.totalPic = filterPic(imgUrl);
    this.$vux.loading.show({
      text: "派对即将开始"
    });

    setTimeout(function() {
      that.$vux.loading.hide();
    }, 6000);
    // debugger
    // var vConsole = new VConsole();
    // console.log('version'+ 1.1)
    let currentTime = window.params.currentTime;
    let overTime = new Date("2019-04-03T10:00:00").getTime();

    // 非app环境下，显示游戏页面，点击下载app
    // var ua = window.navigator.userAgent.toLowerCase();
    console.log(self.params)
    if(self.params.isShare){
      this.$vux.loading.hide();
      this.isShow = 3;
      return;
    }



    ifHomeCake(self.params.personInfo.user_id).then(({ data }) => {
      // 显示

      this.$vux.loading.hide();
      let tempData = data.data;

      // tempData.ifNewUser = 1; // debugger  该用户为邀新用户
      // tempData.playCake = 0; //         用户已开启游戏
      // tempData.eatCake = 1; //         用户已吃过蛋糕
      // tempData.captain = 1; //         用户是否为队长
      // tempData.phoneCoupon = 0; //         用户是否有手机

      window.params.userInfo = tempData;

      // 新用户 且 已创建游戏， 进入游戏界面。
      if (tempData.ifNewUser == 1 && tempData.playCake == 1) {
        if (tempData.eatCake != 1) {
          this.isShow = 4;
          return;
        }
      }

      // 吃过蛋糕，显示已抢过
      if (
        tempData.eatCake &&
        (tempData.captain == 0 || tempData.captain == 1)
      ) {
        //  队长
        this.isObtain = 1;
        this.isTeamObtain = tempData.phoneCoupon ? 1 : 0;
      } else {
        // 队员
        this.isObtain = 1;
        this.isTeamObtain = 1;
      }

      if (tempData.eatCake) {
        this.isShow = 1;
        // debugger
        if (currentTime <= overTime) {
          
          this.showStatu = tempData.phoneCoupon ?  "4" : "5";
        } else {
          this.showStatu = "2";
        }
        return;
      }

      this.isShow = tempData.ifNewUser ? "2" : "4";

      // debugger
      // this.isShow = 3;
    });
  },
  methods: {
    /**
     * 输入手机号页面  返回数据
     */
    receviceData(e) {
      this.isShow = e;
    },

    /**
     * 立即开始  btn
     */
    startBtn() {
      this.isShow = 3;
      if (!window.params.userInfo.playCake) {
        setEstablishCake(self.params.personInfo.user_id).then(({ data }) => {
          this.isShow = 3;
        });
      }
    }
  },
  components: {
    result,
    inputPhone,
    playGameCom
  }
};
</script>
<style lang="less" scoped>
@import "./assets/common";
.container {
  position: relative;
  font-size: 0.32rem;
  .start-btn {
    position: absolute;
    left: 0;
    right: 0;
    margin: 0 auto;
    top: 4.7rem;
    z-index: 6;
    width: 4.58rem;
    height: 0.82rem;
  }
}
</style>


